package tp4;

public class TriRapide extends TabContainer {

	public void triRapide(Integer[] tableau) {
		triRapide(tableau, 0, tableau.length - 1);
		this.tab = tableau;
	}

	private int partition(Integer tableau[], int deb, int fin) {
		int compt = deb;
		int pivot = tableau[deb];

		for (int i = deb + 1; i <= fin; i++) {
			if (tableau[i] < pivot) {
				compt++;
				echanger(tableau, compt, i);
			}
		}
		echanger(tableau, deb, compt);
		return (compt);
	}

	private void echanger(Integer[] tableau, int compt, int i) {
		int temp = tableau[i];
		tableau[i] = tableau[compt];
		tableau[compt] = temp;

	}

	private void triRapide(Integer[] tableau, int deb, int fin) {
		if (deb < fin) {
			int positionPivot = partition(tableau, deb, fin);
			triRapide(tableau, deb, positionPivot - 1);
			triRapide(tableau, positionPivot + 1, fin);
		}
	}


	public void AfficherTabEntier() {
		System.out.println(this);
	}
}
